package com.zth.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zth.pojo.User;
import com.zth.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {
	@Autowired
	private UserService userService;
	
	@RequestMapping("/loginByNameAndPassword")
	public User loginByNameAndPassword(User user,HttpServletRequest request,HttpServletResponse response) {
		User users=userService.loginByNameAndPassword(user);
		request.getSession().setAttribute("user", users);
		return users;
	}
	
	@RequestMapping("/findById")
	public User findById(int id) {
		return userService.findById(id);
	}
	@RequestMapping("/deitPassowrd")
	public int deitPassowrd(User user) {
		
		return userService.deitPassowrd(user);
				
	}
	
	@RequestMapping("/logout")
	public Map<String, Object> logout(HttpServletRequest request,HttpServletResponse response){
		Map<String, Object> map=new HashMap<String, Object>();
		request.getSession().setAttribute("user", null);
		map.put("message", "退出成功");
		return map;
	}
}
